package com.example.mantenimientovehiculo.repostaje;

import com.example.mantenimientovehiculo.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AdaptadorRepostaje extends ArrayAdapter<Repostaje> {

	Activity context;

	private Repostajes todosRepostajes;

	public Repostajes getTodosRepostajes() {
		return todosRepostajes;
	}

	public Repostaje getRepostaje(int index) {
		return this.todosRepostajes.get(index);
	}

	public AdaptadorRepostaje(Activity context, Repostajes misRepostajes) {
		super(context, R.layout.item_historial_repostage, misRepostajes);
		this.context = context;
		this.todosRepostajes = misRepostajes;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View item = convertView;
		if (item == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			item = inflater.inflate(R.layout.item_historial_repostage, null);
		}

		TextView tvFecha = (TextView) item.findViewById(R.id.lblHistorialFecha);
		tvFecha.setText(Repostaje.FormateaFecha(todosRepostajes.get(position)
				.getsFecha()));

		TextView tvKilometros = (TextView) item
				.findViewById(R.id.lblHistorialKm);
		tvKilometros.setText(todosRepostajes.get(position).getiKilometros()
				.toString());

		TextView tvLitros = (TextView) item
				.findViewById(R.id.lblHistorialLitros);
		tvLitros.setText(todosRepostajes.get(position).getDblLitros()
				.toString());

		TextView tvPrecio = (TextView) item
				.findViewById(R.id.lblHistorialPrecio);
		tvPrecio.setText(todosRepostajes.get(position).getDblPrecio()
				.toString());

		TextView tvPrecioTotal = (TextView) item
				.findViewById(R.id.lblHistorialPrecioTotal);
		tvPrecioTotal.setText(todosRepostajes.get(position)
				.getPrecioTotalRepostar().toString());
		
		TextView tvDepositoLleno = (TextView) item.findViewById(R.id.lblHistorialDepositoLleno);
		
		
		if (todosRepostajes.get(position).getbDepositoLleno()){
			tvDepositoLleno.setText(context.getString(R.string.lblHistorialDepositoLleno));
		}else{
			tvDepositoLleno.setText(context.getString(R.string.lblHistorialDepositoVacio));			
		}
		

		return (item);
	}

}